package com.blockmeta.bbs.immodule.greendao;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import com.blockmeta.bbs.immodule.dao.TalkListTop;
import com.blockmeta.bbs.immodule.greendao.db.ChatMessageDao;
import com.blockmeta.bbs.immodule.greendao.db.CircleMemberDao;
import com.blockmeta.bbs.immodule.greendao.db.DaoMaster;
import com.blockmeta.bbs.immodule.greendao.db.IMUserEntityDao;
import com.blockmeta.bbs.immodule.greendao.db.TalkListTopDao;
import com.blockmeta.bbs.immodule.greendao.db.TodoDao;
import com.github.yuweiguocn.library.greendao.MigrationHelper;

import org.greenrobot.greendao.database.Database;

import static com.github.yuweiguocn.library.greendao.MigrationHelper.ReCreateAllTableListener;

/**
 * Created by author on 2019/1/24.
 */

public class AccountUpdateOpenHelper extends DaoMaster.OpenHelper {
    public AccountUpdateOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory) {
        super(context, name, factory);
    }

    @Override
    public void onUpgrade(Database db, int oldVersion, int newVersion) {
        MigrationHelper.migrate(db, new ReCreateAllTableListener() {
            @Override
            public void onCreateAllTables(Database db, boolean ifNotExists) {
                DaoMaster.createAllTables(db, ifNotExists);
            }

            @Override
            public void onDropAllTables(Database db, boolean ifExists) {
                DaoMaster.dropAllTables(db, ifExists);
            }
        }, ChatMessageDao.class, TodoDao.class, IMUserEntityDao.class, TalkListTopDao.class, CircleMemberDao.class);

    }
}
